home *** CD-ROM | disk | FTP | other *** search
/ PC Elektro 3 / PC-Elektro-3-cd1.bin / KBan 2.0 / KBANSRC.LZH / SRC / PROG / KBANDATA / COMPLIST.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-23  |  4.3 KB  |  214 lines

  1. // the implementation of class COMPONENT_LIST
  2. // Copyright (C) 1996, 1997 Kazutaka Hirata <khirata@jove.acs.unt.edu>
  3.  
  4. #include "../finfo.h"
  5. #include "../kbandef.h"
  6.  
  7. #include "complist.h"
  8.  
  9. XY COMPONENT_LIST::get_max() const
  10. {
  11.   XY ac_max(X_MIN, Y_MIN);
  12.   iterator i;
  13.   TRAVERSE(*this, i) {
  14.     ac_max = ::get_max(ac_max, i->get_max());
  15.   }
  16.   return ac_max;
  17. }
  18.  
  19. XY COMPONENT_LIST::get_min() const
  20. {
  21.   XY ac_min(X_MAX, Y_MAX);
  22.   iterator i;
  23.   TRAVERSE(*this, i) {
  24.     ac_min = ::get_min(ac_min, i->get_min());
  25.   }
  26.   return ac_min;
  27. }
  28.  
  29. void COMPONENT_LIST::shift(const XY& ac_dif, COMPONENT_LIST& target) const
  30. {
  31.   iterator i;
  32.   TRAVERSE(*this, i) {
  33.     COMPONENT_ELEMENT shifted;
  34.     i->shift(ac_dif, shifted);
  35.     target.push_back(shifted);
  36.   }
  37. }
  38.  
  39. void COMPONENT_LIST::unselect()
  40. {
  41.   iterator i;
  42.   TRAVERSE(*this, i) {
  43.     i->unselect();
  44.   }
  45. }
  46.  
  47. void COMPONENT_LIST::select_items_in_block(const XY& ac1, const XY& ac2)
  48. {
  49.   iterator i;
  50.   TRAVERSE(*this, i) {
  51.     if(i->is_in_block(ac1, ac2)) {
  52.       i->select();
  53.     }
  54.   }
  55. }
  56.  
  57. void COMPONENT_LIST::collect_selected_items(COMPONENT_LIST& dst) const
  58. {
  59.   iterator i;
  60.   TRAVERSE(*this, i) {
  61.     if(i->is_selected()) {
  62.       dst.push_back(*i);
  63.     }
  64.   }
  65. }
  66.  
  67. void COMPONENT_LIST::remove_selected_items()
  68. {
  69.   iterator i;
  70.   TRAVERSE(*this, i) {
  71.     if(i->is_selected()) {
  72.       iterator current_i = i--;
  73.       erase(current_i);
  74.     }
  75.   }
  76. }
  77.  
  78. int COMPONENT_LIST::load_170(FILE_NEW& fp)
  79. {
  80.   char str[1024];
  81.   fp.gets_wo_return(str, 1024);
  82.   for(;;) {
  83.     long pos = fp.tell();
  84.     fp.gets_wo_return(str, 1024);
  85.     if(!strcmp(str, "end")) {
  86.       break;
  87.     }
  88.     COMPONENT_ELEMENT element;
  89.     fp.seek(pos, SEEK_SET);
  90.     element.load_170(fp);
  91.     push_back(element);
  92.   }
  93.   return true;
  94. }
  95.  
  96. void COMPONENT_LIST::load_200b18(FILE_NEW& fp)
  97. {
  98.   for(;;) {
  99.     char str[1024];
  100.     long pos = fp.tell();
  101.     fp.gets_wo_return(str, 1024);
  102.     if(!strcmp(str, "end")) {
  103.       break;
  104.     }
  105.     COMPONENT_ELEMENT element;
  106.     fp.seek(pos, SEEK_SET);
  107.     element.load(fp);
  108.     push_back(element);
  109.   }
  110. }
  111.  
  112. uint COMPONENT_LIST::load_get_version(FILE_NEW& fp) const
  113. {
  114.   FILE_VERSION fver;
  115.   char str[1024];
  116.   fp.gets_wo_return(str, 1024);
  117.   return fver.get_version_no(str);
  118. }
  119.  
  120. COMPONENT_LIST::LOAD_FUNC_INFO COMPONENT_LIST::load_func_table[] = {
  121.   {FILE_VERSION::VERSION_200B18 , &COMPONENT_LIST::load_200b18},
  122.   {FILE_VERSION::VERSION_UNKNOWN, NULL                        }
  123. };
  124.  
  125. COMPONENT_LIST::LOAD_FUNC COMPONENT_LIST::get_load_func(uint version) const
  126. {
  127.   uint sentinel = FILE_VERSION::VERSION_UNKNOWN;
  128.   uint index = search_info_table(load_func_table, sentinel, version);
  129.   return load_func_table[index].func;
  130. }
  131.  
  132. int COMPONENT_LIST::load(FILE_NEW& fp)
  133. {
  134.   int retval;
  135.   uint version = load_get_version(fp);
  136.   LOAD_FUNC load_func = get_load_func(version);
  137.   if(load_func != NULL) {
  138.     (this->*load_func)(fp);
  139.     retval = true;
  140.   } else {
  141.     retval = false;
  142.   }
  143.   return retval;
  144. }
  145.  
  146. int COMPONENT_LIST::save(FILE_NEW& fp) const
  147. {
  148.   FILE_VERSION fver;
  149.   fp.printf("%s\n", fver.get_version_str(FILE_VERSION::VERSION_200B18));
  150.  
  151.   iterator i;
  152.   TRAVERSE(*this, i) {
  153.     i->save(fp);
  154.   }
  155.  
  156.   fp.puts("end\n");
  157.   return true;
  158. }
  159.  
  160. void COMPONENT_LIST::collect_aperture(APT_TABLE& apt_pin_table, APT_TABLE& apt_line_table) const
  161. {
  162.   iterator i;
  163.   TRAVERSE(*this, i) {
  164.     i->collect_aperture(apt_pin_table, apt_line_table);
  165.   }
  166. }
  167.  
  168. void COMPONENT_LIST::operator+=(const COMPONENT_LIST& target)
  169. {
  170.   insert(end(), target.begin(), target.end());
  171. }
  172.  
  173. COMPONENT_ELEMENT* COMPONENT_LIST::search(const XY& ac)
  174. {
  175.   COMPONENT_ELEMENT* p = NULL;
  176.   iterator i;
  177.   TRAVERSE(*this, i) {
  178.     if(ac.is_in_box(i->get_min(), i->get_max())) {
  179.       p = &*i;
  180.       break;
  181.     }
  182.   }
  183.   return p;
  184. }
  185.  
  186. COMPONENT_ELEMENT* COMPONENT_LIST::search_designator(const char* designator)
  187. {
  188.   COMPONENT_ELEMENT* p = NULL;
  189.   iterator i;
  190.   TRAVERSE(*this, i) {
  191.     if(!strcmp(i->designator(), designator)) {
  192.       p = &*i;
  193.       break;
  194.     }
  195.   }
  196.   return p;
  197. }
  198.  
  199. void COMPONENT_LIST::rotate_90()
  200. {
  201.   iterator i;
  202.   TRAVERSE(*this, i) {
  203.     i->rotate_90();
  204.   }
  205. }
  206.  
  207. void COMPONENT_LIST::limit_drill_size(uint drill)
  208. {
  209.   iterator i;
  210.   TRAVERSE(*this, i) {
  211.     i->limit_drill_size(drill);
  212.   }
  213. }
  214.